package com.cn.springcloudwechat.controller.personalcenter;

import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.utils.base.Const;
import com.cn.springcloudwechat.controller.vaccine.log.LogInfo;
import com.cn.springcloudwechat.controller.vaccine.log.OperateType;
import com.cn.springcloudwechat.model.dto.AreaDto;
import com.cn.springcloudwechat.model.dto.StationDto;
import com.cn.springcloudwechat.service.personalcenter.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/areaController")
public class AreaControllerH {


    @Autowired
    AreaService areaService;




    /**
     * 获取行政区划（后台）
     * @param ajaxRes
     * @return
     */
    @RequestMapping("/getArea")
    @LogInfo(operateType = OperateType.UPDATE, content = "获取行政区划（后台）")
    public AjaxRes getArea(AjaxRes ajaxRes){
        try{
            Map<String,Object> areaDdto = areaService.getArea();
            ajaxRes.setSucceed(areaDdto,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }




    /**
     * 获取行政区划（后台）
     * @param ajaxRes
     * @return
     */
    @RequestMapping("/getAreaByParentId")
    @LogInfo(operateType = OperateType.UPDATE, content = "获取行政区划（后台）")
    public AjaxRes getAreaByParentId(AjaxRes ajaxRes,String parentId){
        try{
            List<AreaDto> areaDdtos = areaService.getAreaByPerentId(parentId);
            ajaxRes.setSucceed(areaDdtos,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }

    /**
     * 查询省集合
     * @param ajaxRes
     * @return
     */
    @RequestMapping("/getProvince")
    public AjaxRes getProvince(AjaxRes ajaxRes){
        try{
            List<AreaDto> areaDdtos = areaService.getProvince();
            ajaxRes.setSucceed(areaDdtos,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }


}
